package com.npl.demonplservice;

//import com.npl.demonplservice.metaclass.Config;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

@RequestMapping("/nlpservice")
@RestController
class Controller {
    @CrossOrigin(origins = "*")
    @RequestMapping(value = "/textinput", method = RequestMethod.POST)
    public void nplProcessing(@RequestBody String text, @Autowired HttpServletRequest request) throws IOException {
        System.out.println("POST /textquery text= " + text);
        //对中文query分词，依据StanfordNLPParser
        List<String> words = Segmentation.segInCh(text);
        //与历史query比对，获得当前用户输入query可能想要的操作函数类型（regression／average）
        String topic = Topic.gettopic(words);
        //将用户输入的query保存
        SaveNewsentenceWithTag.save(text, topic);
        //向推荐模块发送可能的query函数类型
        if (topic.equals("regression")) {topic=new String("Regression");}
        else {topic=new String("Average");}
        SendMessage sm = new SendMessage();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("user_intention", topic);

        sm.makePost(new URL("http://10.141.212.118:"+sm.rmport+"/rec"),
                jsonObject.toString());
        System.out.println(jsonObject.toString());
        return;
    }
}

